<?php

// no direct access
defined('_JEXEC') or die('Restricted access');

// check evolve_library is installed
if (!file_exists(JPATH_PLUGINS.'/system/evolvelibrary.php')) {
	// can't do much without it
	jimport('joomla.error.log');
	
	$errorLog = 'syncr_client-error_log-'.date('Y-m-d').'.log.php';
	
    $options = array(
        'format' => "{DATE}\t{TIME}\t{COMMENT}"
    );
    // Create the instance of the log file in case we use it later
    $log = &JLog::getInstance($errorLog, $options);
    $log->addEntry(array('comment' => 'evolve library not loading'));
	
	JError::raiseWarning(404, JText::_('JEVOLVE_LIBRARY_MISSING'));
	return;
}

// load evolve_library
require_once JPATH_PLUGINS.'/system/evolvelibrary.php';

$evl = new evolveLibrary;

// check evolve_library is enabled
if (!$evl->enabled()) {
	// can't do much without it
	JError::raiseWarning(500, JText::_('JEVOLVE_LIBRARY_DISABLED'));
	return;
}

// enabled logging
$log = $evl->loadHelper('log');

// default controller name and path
$controllerName = 'SyncrController';
$controllerPath = JPATH_COMPONENT.'/controller.php';
	
if (file_exists($controllerPath)) {
	require_once $controllerPath;
} else {

	$log->simpleLog('syncr.php: invalid controller', 'syncr');
	JError::raiseError(500, 'Invalid controller');
}

// create controller instance
if (class_exists($controllerName)) {
	$controller = new $controllerName();
} else {
	$log->simpleLog('syncr.php: invalid controller class', 'syncr');
	JError::raiseError(500, 'Invalid controller class');
}

$controller->execute(JRequest::getCmd('task'));
$controller->redirect();